package com.cjh.admin.controller;

import com.alibaba.fastjson.JSON;
import com.cjh.admin.config.TokenThreadLocal;
import com.cjh.common.dto.StoreOrderPagingDTO;
import com.cjh.common.dto.UpdateOrderStautsDTO;
import com.cjh.common.enums.StatusEnum;
import com.cjh.common.response.Result;
import com.cjh.common.service.StoreOrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cjh
 * @since 2021-11-15
 */
@RestController
@RequestMapping("/order")
public class StoreOrderController {
    @Autowired
    StoreOrderService storeOrderService;
    @ApiOperation("获取所有订单")
    @GetMapping("/getPagingStore")
    public Result getPagingStore(@RequestParam String storeOrderPagingDTO){
        StoreOrderPagingDTO storeOrderPagingDTO1 = JSON.parseObject(storeOrderPagingDTO, StoreOrderPagingDTO.class);
        storeOrderPagingDTO1.setUsername(TokenThreadLocal.get());
        return storeOrderService.getPagingStore(storeOrderPagingDTO1);
    }
    @ApiOperation("根据订单id获取订单")
    @GetMapping("/getStoreByOrderId")
    public Result getStoreByOrderId(@RequestParam Integer orderId){
        return storeOrderService.getStoreByOrderId(orderId);
    }

    @ApiOperation("根据订单id修改订单状态")
    @PostMapping("/updateOrderStautsByOrderId")
    public Result updateOrderStautsByOrderId(@RequestBody List<UpdateOrderStautsDTO> updateOrderStautsDTOList){
        return storeOrderService.updateOrderStautsByOrderId(updateOrderStautsDTOList);
    }

    @ApiOperation("修改订单备注")
    @GetMapping("/updateOrderRemarksByOrderId")
    public Result updateOrderRemarksByOrderId(@RequestParam Integer orderId,@RequestParam String merchantRemarks){
        return storeOrderService.updateOrderRemarksByOrderId(orderId,merchantRemarks);
    }
}
